﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Informant.Clients.UI.Wpf4.Controls
{
	/// <summary>
	/// Interaction logic for WaitCursor.xaml
	/// </summary>
	public partial class WaitCursor : UserControl
	{
		#region DependencyProperties

		/// <summary>
		/// Gets or sets a value indicating whether this instance is active.
		/// </summary>
		/// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
		public Boolean IsActive
		{
			get { return (Boolean)GetValue(IsActiveProperty); }
			set { SetValue(IsActiveProperty, value); }
		}
		// Using a DependencyProperty as the backing store for IsActive.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty IsActiveProperty =
			DependencyProperty.Register("IsActive", typeof(Boolean), typeof(WaitCursor), new UIPropertyMetadata(false, IsActiveChangedCallback));
		static void IsActiveChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			WaitCursor waitCursor = d as WaitCursor;
			if (waitCursor != null)
			{
				if ((Boolean)e.NewValue)
				{
					waitCursor.OnActivated();
				}
				else
				{
					waitCursor.OnDeactivated();
				}
			}
		}

		#endregion

		#region RoutedEvents

		/// <summary>
		/// Fired when IsActive is set to true;
		/// </summary>
		public event RoutedEventHandler Activated
		{
			add { AddHandler(ActivatedEvent, value); }
			remove { RemoveHandler(ActivatedEvent, value); }
		}
		public static readonly RoutedEvent ActivatedEvent =
			EventManager.RegisterRoutedEvent("Activated", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(WaitCursor));
		private void OnActivated()
		{
			RaiseEvent(new RoutedEventArgs(WaitCursor.ActivatedEvent));
		}

		/// <summary>
		/// Fired when IsActive is set to false;
		/// </summary>
		public event RoutedEventHandler Deactivated
		{
			add { AddHandler(DeactivatedEvent, value); }
			remove { RemoveHandler(DeactivatedEvent, value); }
		}
		public static readonly RoutedEvent DeactivatedEvent =
			EventManager.RegisterRoutedEvent("Deactivated", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(WaitCursor));
		private void OnDeactivated()
		{
			RaiseEvent(new RoutedEventArgs(WaitCursor.DeactivatedEvent));
		}

		#endregion

		public WaitCursor()
		{
			InitializeComponent();
		}
	}
}
